<?php 
	Class Activitybanner extends CI_Controller{
		public function __construct(){
			parent::__construct();
			$this->load->model("model_activitybanner");
			$this->load->model("model_activity");
		}
		
		public function index(){
			if(isset($_GET['activityid'])){
				$data['activity']=$this->model_activity->getdata(intval($_GET['activityid']));	
				$data['data']=$this->model_activitybanner->getallbyactivityid(intval($_GET['activityid']));
			}else header('Location: '.base_url().'admin/activity/index');			
			
			$data["template"]="activity/activity_banner";
			$this->load->view("layout",$data);	
		}
		public function edit(){
			$data['activity']=$this->model_activity->getdata(intval($_GET['activityid']));
			if(isset($_GET['id'])) $data['data']=$this->model_activitybanner->getdata(intval($_GET['id']));	
			else $data['data']=NULL;
			
			$data['template']="activity/activitybanner_edit";
			$this->load->view("layout",$data);	
		}
		public function update(){
			if(isset($_GET['id'])){
				if($_FILES['fuavatar']['name'] != NULL){
                    $config['upload_path'] = './uploads/activitybanner';
                    $config['allowed_types'] = '*';
                    $config['max_size']	= '3000';
                    $config['max_width']  = '2704';
                    $config['max_height']  = '2700';
                    $this->load->library('upload',$config);
                    if(!$this->upload->do_upload("fuavatar")){
                        header('Location: '.base_url().'admin/activity/index');
                        return FALSE;
                    }else{
                        $dataimg = $this->upload->data();
                        $data['avatar'] = $dataimg['file_name'];
                    }
                }
				$data['status']=$_POST['status'];
				$data['activityid']=$_GET['activityid'];
				$this->model_activitybanner->update($data,intval($_GET["id"]));
				header('Location: '.base_url().'admin/activitybanner/index?activityid='.intval($_GET['activityid']));
			}	
		}
		public function insert(){
			if($_FILES['fuavatar']['name'] != NULL){
				$config['upload_path'] = './uploads/activitybanner';
				$config['allowed_types'] = '*';
				$config['max_size']	= '3000';
				$config['max_width']  = '2704';
				$config['max_height']  = '2700';
				$this->load->library('upload',$config);
				if(!$this->upload->do_upload("fuavatar")){
					header('Location: '.base_url().'admin/activitybanner/index?activityid='.intval($_GET['activityid']));
					return FALSE;
				}else{
					$dataimg = $this->upload->data();
					$data['avatar'] = $dataimg['file_name'];
				}
			}
			$data['status']=$_POST['status'];
			$data['activityid']=intval($_GET['activityid']);
			$this->model_activitybanner->add($data);				
			header('Location: '.base_url().'admin/activitybanner/index?activityid='.intval($_GET['activityid']));
		}
		
		public function delete(){
			if(isset($_GET["id"])){
                $data = $this->model_activitybanner->getdata(intval($_GET['id']));
                @unlink("uploads/activitybanner/".$data['avatar']);
                $this->model_activitybanner->del(intval($_GET["id"]));
				header('Location: '.base_url().'admin/activitybanner/index?activityid='.intval($_GET['activityid']));
			}	
		}
		public function changestatus(){
			if(isset($_GET['status'])){
				$data['status']=intval($_GET['status']);
				$this->model_activitybanner->update($data,intval($_GET['id']));
				header('Location: '.base_url().'admin/activitybanner/index?activityid='.intval($_GET['activityid']));
			}	
		}
	}
?>